package com.knightcloud.micro.auth.security.impl;

import com.knightcloud.common.base.vo.response.R;
import com.knightcloud.micro.auth.config.security.LoginUser;
import com.knightcloud.micro.upms.api.dto.SysUserDto;
import com.knightcloud.micro.upms.api.feign.RemoteUserService;
import lombok.AllArgsConstructor;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

/**
 * 重写加载用户
 *
 * @author knight
 */
@Service
@AllArgsConstructor
public class UserDetailsServiceImpl implements UserDetailsService {

	/**
	 * 系统用户服务
	 */
	private final RemoteUserService remoteUserService;

	@Override
	public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
		R<SysUserDto> userDtoR = remoteUserService.selectSysUserByUsername(username);
		return new LoginUser(userDtoR.getData());
	}

}
